import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SensorVO, SensorForm, SensorQuery } from '@/api/hardware/sensor/types';

/**
 * 查询传感器列表
 * @param query
 * @returns {*}
 */

export const listSensor = (query?: SensorQuery): AxiosPromise<SensorVO[]> => {
  return request({
    url: '/hardware/sensor/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询传感器详细
 * @param id
 */
export const getSensor = (id: string | number): AxiosPromise<SensorVO> => {
  return request({
    url: '/hardware/sensor/' + id,
    method: 'get'
  });
};

/**
 * 新增传感器
 * @param data
 */
export const addSensor = (data: SensorForm) => {
  return request({
    url: '/hardware/sensor',
    method: 'post',
    data: data
  });
};

/**
 * 修改传感器
 * @param data
 */
export const updateSensor = (data: SensorForm) => {
  return request({
    url: '/hardware/sensor',
    method: 'put',
    data: data
  });
};

/**
 * 删除传感器
 * @param id
 */
export const delSensor = (id: string | number | Array<string | number>) => {
  return request({
    url: '/hardware/sensor/' + id,
    method: 'delete'
  });
};

/**
 * 传感器状态修改
 * @param id ID
 * @param status 状态
 */
export const changeSensorStatus = (id: number | string, status: string) => {
  const data = {
    id,
    status
  };
  return request({
    url: '/hardware/sensor/changeStatus',
    method: 'put',
    data: data
  });
};

export const sensorsTreeselect = (): AxiosPromise<SensorVO[]> => {
  return request({
    url: '/hardware/sensor/treeselect',
    method: 'get'
  });
};



// export default [listSensor, getSensor, addSensor, updateSensor, delSensor, changeSensorStatus];
